<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
      .active {
        color: red;
      }
    </style>
  </head>

  <body>
    <div id="app"></div>
    <script src="https://unpkg.com/react@^16/umd/react.production.min.js"></script>
    <script src="https://unpkg.com/react-dom@16.13.0/umd/react-dom.production.min.js"></script>
    <script src="https://unpkg.com/babel-standalone@6.26.0/babel.js"></script>
    <script type="text/babel">
      // react class类型的组件
      class Home extends React.Component {
        constructor(props) {
          super(props)
          // class组件的数据位置
          this.state = {
            name: '阿三',
            age: 88,
            list: ['银川', '北京', '郑州', '陕西']
          }
        }
        say = () => {
          console.log(this.state.name)
          alert('我的名字')
        }
        // this指向改变了  需要绑定this指向
        // say() {
        //   console.log(this.state.name)
        //   alert(111)
        // }
        run() {
          console.log(this.state.list)
          console.log(this.props.tianqi)
        }

        render() {
          if (this.props.tianqi == '晴朗') {
            //组件内部不修改props
            // this.props.tianqi = '闷热'
          }
          // react 生命周期 渲染中

          return (
            <div>
              <div onClick={this.say}>我的名字：{this.state.name}</div>
              <div onClick={this.run.bind(this)}>
                我的年龄：{this.state.age}
              </div>
              <div className={this.props.flag ? 'active' : ''}>
                今天天气：{this.props.tianqi}
              </div>
              <ul>
                {this.state.list.map((item, index) => (
                  <li key={index}>
                    <span>{index}</span>
                    <span>{item}</span>
                  </li>
                ))}
              </ul>
            </div>
          )
        }
      }
      function Nav(param) {
        return <Home tianqi="打雷" flag={false} />
      }

      ReactDOM.render(
        <div>
          <Nav />
          <Home tianqi="晴朗" flag={true} />
        </div>,
        document.getElementById('app')
      )
    </script>
  </body>
</html>
